/*  Based on "Hosp diff May 06 step1.do"  Doug Staiger jss modified*//*  program to get risk adjusted cost and mortality at hosp level *//*   and also get the necessary other statistics for later filtering *//* Mar 2007 & Nov 07 *//* goes back to 86*//*  you need to set some globals at the beginning *//* SETUP -- SET THE DIRECTORY, MEMORY */cd "/jss/Staiger Productivity/"clearcapture log closelog using "stage1_hosp_nov07.log", text replaceset mem 800mset more off* SET GLOBALS -- DEP VAR, CONTROLS, ETC global id_hosp "provider"* 2. the dependent variables -- mortality, part A cost, and total cost global depvar "dead1yr"* 3. the control variables for each cohort: global covar_ami "$asrace $riskadj"/* this global determines the minimum size threshold *//* threshold = cut prior to 92, and 5*cut 92-04 */global cut=1set mem 1200mset matsize 800use  "/jss/Trend/ami/Unified_ami/unified_ami8604.dta",cleardrop if mi == 1drop if i_hmo==1* Goes back*drop if year < 1992*  Create an extract*  keep if 500*int(_n/500) == _ntab year, gen(yr)rename sum_ptareimbrs partarename sum_icudays icurename sum_ccudays ccudestring dx1, replacegen dxshort = int(dx1/10) if dx1 > 5000replace dxshort = dx1 if dx1 <= 5000gen anterlat  = (dxshort==4100)gen antwall   = (dxshort==4101)gen inflat    = (dxshort==4102)gen infpost   = (dxshort==4103)gen infwall   = (dxshort==4104)gen latnec    = (dxshort==4105)gen truepost  = (dxshort==4106)gen subend   = (dxshort==4107)gen aminec    = (dxshort==4108)gen aminos    = (dxshort==4109)* Create age-sex-race variablesgen iage=recode(age,69,74,79,84,110)egen iasr = group(sex race iage)tab iasr, gen(asr)*  Collapse a few variablesgen diabetes = (diabet1==1 | diabet2 == 1)gen liver = (liver1==1 | liver2==1)gen cancerall = (cancer==1 | metast==1)#del;global riskadj "vascul pulmon dementia diabetes liver renal cancerall anterlat antwall inflat infpost infwall latnec truepost subend aminec aminos";#del cr;global year04    "yr2-yr19"global asrace "asr2-asr30"global covar_ami "$asrace $riskadj"* Running regressions to get Hospital-specific effectsgen dead1yr = (survdays < 365) gen dead6m  = (survdays < 183)gen dead30d = (survdays <  30)gen dead7d  = (survdays <   7)* create id variable that is hospital-by-year egen idx = group(provider year)compresssumm $depvar $riskadj agetab year, summ($depvar)tab sextab racetab iage/* now select the sample */sort providersave temp, replacegen nobs=1summ nobscollapse (sum) nobs, by(provider year)gen flag_cut = 0replace flag_cut = 1 if nobs<$cut & year<1992replace flag_cut = 1 if nobs<(5*$cut) & year>=1992egen min_nobs_cut = max(flag_cut), by(provider)gen one=1egen tot_yrs = sum(one), by(provider)gen insamp = (min_nobs_cut==0 & tot_yrs==19)tab year insamptab year insamp [fw=nobs]keep if insamp==1tab yeartab year insamp [fw=nobs]keep if year==1994keep providersort providersave id_insamp, replaceuse temp, clearmerge provider using id_insamptab _mergekeep if _merge==3drop _merge       /* 1. RUN THE BASIC REGRESSION  */            areg $depvar $covar_ami, absorb(idx)            /* save the root mean square error of the regression */             gen rmse_hosp_ami = e(rmse)              /* save the FE, which is the risk-adjusted estimate */             predict fe_hosp_ami if e(sample), d              /* saves the # obs on which FE was based */             egen nobs_hosp_ami = count(fe_hosp_ami) if fe_hosp_ami !=., by(idx)        * COSTS* First, adjust prices using a very simple neanderthal approachgen     adj =  .712 if year == 1986replace adj =  .732 if year == 1987replace adj =  .757 if year == 1988replace adj =  .786 if year == 1989replace adj =  .816 if year == 1990replace adj =  .844 if year == 1991replace adj =  .864 if year == 1992replace adj =  .884 if year == 1993replace adj =  .903 if year == 1994replace adj =  .921 if year == 1995replace adj =  .939 if year == 1996replace adj =  .954 if year == 1997replace adj =  .965 if year == 1998replace adj =  .979 if year == 1999replace adj = 1.000 if year == 2000replace adj = 1.024 if year == 2001replace adj = 1.041 if year == 2002replace adj = 1.060 if year == 2003replace adj = 1.082 if year == 2004* Norm to year 2004replace adj = adj/1.082replace parta1y  = parta1y/adj /* 2.  RUN THE COST REGRESSION  */            areg parta1y $covar_ami, absorb(idx)            /* save the root mean square error of the regression */             gen rmse_cost = e(rmse)              /* save the FE, which is the risk-adjusted estimate */             predict hosp_cost if e(sample), d /* 2.  RUN THE DRG REGRESSION  */            areg drgwgt1y $covar_ami, absorb(idx)            gen rmse_drg = e(rmse)             predict hosp_drg if e(sample), d sum $riskadj if year <=2004        /* collapse and save the data */  collapse (mean) dead1yr rmse_* hosp_cost parta1y hosp_drg drgwgt1y fe_* nobs_*, by(provider year)  sort provider  save fe_ami_hosp_86_nov07, replaceset more onlog close